#!/usr/bin/sh
#
# Script that archives gnc binaries and std libraries.

# Files and directories to be stored.

gnc="gnc-s2"
lib="libgordon-s2.a"
std="std"

# Pieces of information to be stored.

gnc_version_phrase="$(./$gnc --version)"
gnc_version="$(./$gnc --version | awk '{print $2}')"

date="$(date +%Y-%m-%d)"
commit="$(git log -1 --pretty=oneline --abbrev-commit --abbrev=10 | awk '{print $1}')"
hash_gnc="$(sha1sum $gnc | awk '{print $1}')"
hash_lib="$(sha1sum $lib | awk '{print $1}')"

# Output locations.

arcdirbase=~/.gordon/archive
arcname="gordon-$date-$commit"
arcdir=$arcdirbase/$arcname

# The action.

echo "storing to: $arcdir"
mkdir -p $arcdir
cp $gnc $arcdir/gnc
cp $lib $arcdir/libgordon.a
cp -r $std $arcdir/

echo "$gnc_version_phrase / $arcname:"  >> $arcdir/info.txt
echo ""                                 >> $arcdir/info.txt
echo "$hash_gnc gnc"                    >> $arcdir/info.txt
echo "$hash_lib libgordon.a"            >> $arcdir/info.txt

# TODO: Format this properly with paddings.
echo "$date  $commit  $gnc_version         $hash_gnc    $hash_lib" >> $arcdirbase/info.txt
